// pages/account/index.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    avatarUrl: null,
    warnSize: 'default',
    disabled: true,
    loading: false,
    phone: ''
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //获得dialog组件
    this.dialog = this.selectComponent("#dialog");    
  },

  showDialog() {
    this.dialog.showDialog();
  },
  //取消事件
  _cancelEvent() {
    console.log('你点击了取消');
    this.dialog.hideDialog();
  },

  onLoad: function () {
    var that = this;
    var avatarUrl = wx.getStorageSync(app.cacheKey.userInfo_avatarUrl)||'/images/defaultHead.jpg';
    that.setData({
      avatarUrl: avatarUrl
    })
  },
  /**
   * 设置phone
   */
  setPhone: function(e) {
    this.setData({
      phone: e.detail.value
    })
    if (this.data.phone.length === 11) {
      this.setDisabled(false);
    } else {
      this.setDisabled(true);
    }
  },
  /**启用禁用按钮 */
  setDisabled: function(b) {
    this.setData({
      disabled: b
    })
  },
  setPlain: function(e) {
    this.setData({
      plain: !this.data.plain
    })
  },
  setLoading: function(e) {
    this.setData({
      loading: !this.data.loading
    })
  },
  onGotUserInfo: function(e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.userInfo)
    console.log(e.detail.rawData)
  },
  /**
   * 下一步，获取验证码
   */
  next: function(e) {
    var that = this;
    if (!that.data.phone || that.data.phone.length != 11) {
      wx.showToast({
        title: '请输入有效的手机号',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    wx.navigateTo({
      url: '/pages/account/login?phone=' + (that.data.phone)
    })
  }
})